﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Collections.Generic;
using DataAccess;
using ThuatToanTachTuKhoa;


namespace Business
{
    public class XL_TraCuuDiaDiem
    {
        private XL_TuKhoa m_XLTuKhoa = new XL_TuKhoa();

        public XL_TraCuuDiaDiem(DataTable DanhSachTenDuong , DataTable DanhSachTenDiaDiem ,DataTable DanhSachDichVu)
        {
            List<String> CacTenDuong = new List<string>();

            for (int index = 0; index < DanhSachTenDuong.Rows.Count; ++index)
            {
                String TenDuong = DanhSachTenDuong.Rows[index]["TenDuong"].ToString();
                CacTenDuong.Add(TenDuong);
            }

            List<String> CacTenDiaDiem = new List<string>();

            for (int index = 0; index < DanhSachTenDiaDiem.Rows.Count; ++index)
            {
                String TenDiaDiem = DanhSachTenDiaDiem.Rows[index]["TenDiaDiem"].ToString();
                CacTenDiaDiem.Add(TenDiaDiem);
            }

            List<String> CacDichVu = new List<string>();

            for (int index = 0; index < DanhSachDichVu.Rows.Count; ++index)
            {
                String TenDichVu = DanhSachDichVu.Rows[index]["TenDichVu"].ToString();
                CacDichVu.Add(TenDichVu);
            }

            m_XLTuKhoa.CacTenDichVu = CacDichVu;
            m_XLTuKhoa.CacTenDiaDiem = CacTenDiaDiem;
            m_XLTuKhoa.CacTenDuong = CacTenDuong;
        }

        public List<DiaDiemDTO> tracuuDiaDiem(String TuKhoa)
        {
            TuKhoa.Trim();
            TuKhoa = m_XLTuKhoa.chuanHoaTuKhoa(TuKhoa);

            String TenDichVu = m_XLTuKhoa.tachTenDichVu(TuKhoa);

            if ("" != TenDichVu)
            {
                return tracuuDiaDiem(TenDichVu, TuKhoa);
            }

            return new List<DiaDiemDTO>();
        }

        public List<DiaDiemDTO> tracuuDiaDiem(String TenDichVu, String TuKhoa)
        {
            TuKhoa.Trim();
            TuKhoa = m_XLTuKhoa.chuanHoaTuKhoa(TuKhoa);

            String TenDiaDiem = m_XLTuKhoa.tachTenDiaDiem(TuKhoa);
            String TenDuong = m_XLTuKhoa.tachTenDuong(TuKhoa);

            DataTable QueryResult = new DataTable();

            if ("" == TenDuong && "" == TenDiaDiem)
            {
                QueryResult = DiaDiemDAO.DAO.tracuuDiaDiemDichVu(TenDichVu);
            }

            if (null == TenDiaDiem || "" == TenDiaDiem)
            {
                if (!(null == TenDuong || "" == TenDuong))
                {
                    QueryResult = DiaDiemDAO.DAO.tracuuDiaDiemDichVuTheoTenDuong(TenDichVu, TenDuong);
                }
            }
            else
            {
                if (null == TenDuong || "" == TenDuong)
                {
                    QueryResult = DiaDiemDAO.DAO.tracuuDiaDiemDichVuTheoTenDiaDiem(TenDichVu,TenDiaDiem);
                }
                else
                {
                    QueryResult = DiaDiemDAO.DAO.tracuuDiaDiemDichVu(TenDichVu,TenDuong,TenDiaDiem);
                }

            }

            return DiaDiemDTO.TaoDanhSachDiaDiem(QueryResult);
        }
    }
}
